package com.survey.Controller;

import com.survey.pojo.data.SurveyDO;
import com.survey.pojo.vo.SurveyVO;
import com.survey.service.SurveyService;
import com.survey.utils.PageBean;
import com.survey.utils.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class surveyAudiController {
    @Autowired
    SurveyService surveyService;
    @RequestMapping("/surveyAudi/list")
    public String list(Model model, SurveyVO query) throws Exception {
        //SurveyVO query=new SurveyVO();
        //List<SurveyVO> list=surveyService.listAllSurvey();
        int PageSize=5;

        int Size=5;
        query.setPageSize(PageSize);
        query.setSize(Size);
        query.setIsopen(1);
        PageBean<SurveyVO> pageBean=surveyService.listSurvey(query);
        model.addAttribute("pageBean", pageBean);
        return "/admin/SurveyAudi.jsp";

    }
    @RequestMapping("/surveyAudi/through")
    @ResponseBody
    public Result through(Integer id) throws Exception {
        SurveyVO query=new SurveyVO();
        query.setId(id);
        SurveyDO surveyDO = surveyService.findDetailSurvey(query);

        BeanUtils.copyProperties(query,surveyDO);
        query.setIscheck(1);
        return  surveyService.updateSurvey(query);
    }
    @RequestMapping("/surveyAudi/ban")
    @ResponseBody
    public Result ban(Integer id) throws Exception {
        SurveyVO query=new SurveyVO();
        query.setId(id);
        SurveyDO surveyDO = surveyService.findDetailSurvey(query);

        BeanUtils.copyProperties(query,surveyDO);
        query.setIscheck(0);
        return  surveyService.updateSurvey(query);
    }
}
